package com.ny.mapper;

import com.ny.entity.Device;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DeviceMapper {
    @Select("SELECT * FROM device")
    @Results({
            @Result(property = "deviceId", column = "device_id"),
            @Result(property = "deviceSn", column = "device_sn"),
            @Result(property = "deviceName", column = "device_name"),
            @Result(property = "deviceType", column = "device_type"),
            @Result(property = "roomId", column = "room_id"),
            @Result(property = "status", column = "status"),
            @Result(property = "protocol", column = "protocol"),
            @Result(property = "createdTime", column = "created_time")
    })
    List<Device> findAllDevices();

    // 添加根据设备名称查询设备信息的方法
    @Select("SELECT * FROM device WHERE device_name LIKE CONCAT('%', #{deviceName}, '%')")
    @Results({
            @Result(property = "deviceId", column = "device_id"),
            @Result(property = "deviceSn", column = "device_sn"),
            @Result(property = "deviceName", column = "device_name"),
            @Result(property = "deviceType", column = "device_type"),
            @Result(property = "roomId", column = "room_id"),
            @Result(property = "status", column = "status"),
            @Result(property = "protocol", column = "protocol"),
            @Result(property = "createdTime", column = "created_time")
    })
    List<Device> findDevicesByName(String deviceName);
}
